#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include <string.h>
#include <sys/socket.h>   // For Socket Functions
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>

#include "util.h"
#include "server_utils.h"

/* May be convert this into signal handler
 to do out of bank check stats on server.
*/
static
void print_stats (void)
{
    LOG(DEBUG, "Server start time: %d", g.server_start_time);
    LOG(DEBUG, "Total number of requests handled so far: ");
    LOG(DEBUG, "Max Sessions Allowed: ");
    LOG(DEBUG, "Max Watermark: ");
    LOG(DEBUG, "Min Watermark: ");
    LOG(DEBUG, "Avg Session duration: ");
    LOG(DEBUG, "Max duration session: ");
}

static
void print_config (void)
{
	LOG(INFO,"");
}



/* Public routines */
void
handle_admin_request (int fd)
{
    /*
     * 1. Accept the conection
     * 2. handle the request here.
     */
    int cSocket = -1;
    socklen_t len = 0;
    struct sockaddr_in cAddress;
    char client_ip[INET_ADDRSTRLEN + 1];
    char line[1024];

    LOG(DEBUG, "Inside handle_connect_request");
            memset((void *)&cAddress, 0, sizeof(struct sockaddr_in));

    cSocket = accept(fd, (struct sockaddr*) &cAddress, &len);
    if (cSocket == -1){
        LOG(ERROR,"Failed in accept with error: %d", errno);
        return;
    }

	//read request : read_line

    /*
     * 1. "print_config"
     * 2. "print_stats"
     * 3. "shutdown"
     */



    //close connection.

    LOG(DEBUG, "Connection from %s, port %d\n",
        inet_ntop(AF_INET, &cAddress.sin_addr, client_ip,
                  sizeof(client_ip)), ntohs(cAddress.sin_port));
    LOG(DEBUG, "Assigned socket %d for the client", cSocket);
    // condtion broadcast

}
